package com.ydd.controller.admin;

import com.ydd.dto.SYSUserDTO;
import com.ydd.dto.SYSUserPageQueryDTO;
import com.ydd.entity.SysUser;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.SysUserService;
import com.ydd.vo.SysUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author fang
 * @Date 2023-05-29 16:43
 */
@Api(tags = "权限管理-用户管理")
@RestController
@RequestMapping("/admin/sys_user")
@Slf4j
public class SysUserController {
    @Autowired
    SysUserService sysUserService;

    /**
     * 新增管理员
     * @param sysUserDTO
     * @return
     */
    @PostMapping("/add")
    @ApiModelProperty("新增管理员")
    public Result userAdd(@RequestBody SYSUserDTO sysUserDTO){
        log.info("新增管理员:{}",sysUserDTO);
        sysUserService.userAdd(sysUserDTO);
        return Result.success();
    }

    /**
     * 分页查询
     * @param sysUserPageQueryDTO
     * @return
     */
    @GetMapping("/list")
    @ApiModelProperty("管理员列表分页")
    public Result<PageResult >userList(SYSUserPageQueryDTO sysUserPageQueryDTO){
        log.info("分页查询：{}",sysUserPageQueryDTO);
        PageResult sysUserList= sysUserService.page(sysUserPageQueryDTO);
        return Result.success(sysUserList);
    }

    /**
     * 删除管理员
     * @param id
     * @return
     */
    @GetMapping("/del")
    @ApiModelProperty("管理员删除")
    public Result userDel(String id){
        log.info("删除管理员：{}",id);
        sysUserService.del(id);
        return Result.success();
    }

    /**
     * 管理员详情
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiModelProperty("管理员详情")
    public Result<SysUserVO> getUser(String id){
        log.info("查询管理员详情：{}",id);
        SysUserVO user = sysUserService.getUser(id);
        return Result.success(user);
    }

    /**
     * 管理员修改
     * @param sysUserDTO
     * @return
     */
    @PostMapping("/update")
    @ApiModelProperty("管理员修改")
    public Result updateUser(@RequestBody SYSUserDTO sysUserDTO){
        log.info("管理员修改：{}",sysUserDTO);
        sysUserService.upUser(sysUserDTO);
        return Result.success();
    }
}
